/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Services;

import DAO.DAOFactory;
import DAO.Financial.QuoteDAO;
import DAO.Financial.StockDAO;
import DAO.exceptions.PreexistingEntityException;
import FinancialEntity.Quote;
import FinancialEntity.Stock;
import VO.QuotesVO;
import VO.StockVO;
import java.util.ArrayList;
import java.util.List;
import javax.persistence.EntityManager;

/**
 *
 * @author Sebastian
 */
public class QuoteServices {
    
        public void createQuote(QuotesVO quoteVo, EntityManager em ) throws PreexistingEntityException, Exception{
        QuoteDAO quotedao = (QuoteDAO) DAOFactory.getDAOFinancial(DAOFactory.QUOTE);
        quotedao.create(quoteVo.toEntity(), em);
    }
    
    public List<QuotesVO> getAllQuotes(EntityManager em){
        QuoteDAO quotedao = (QuoteDAO) DAOFactory.getDAOFinancial(DAOFactory.QUOTE);
        List<Quote> listaQuotes = quotedao.findQuoteEntities(em);
        List<QuotesVO> listaVos = new ArrayList<>();
        for (Quote m:listaQuotes){
            listaVos.add(m.toVO());
        }
        return listaVos;
    }
    
}
